<?php
$menus = config_menus();
$uri = config_item('enable_lang') ? 2 : 1;
$segmens = $this->uri->segment($uri , '');

//以下是权限控制模块

$rolePermission = $this->permission;//获取权限
//print_r($rolePermission);
$result = $this->uri->segments;
//如果有语言包则去除第一个参数
if (config_item('enable_lang')) {
    array_shift($result);
}
//如果有分页，则去除分页
if (count($result) == 4) {
    array_pop($result);
}
$cur_data_id = implode('_' , $result);//这个获取当前的url

?>
<div class="left">
<?php
foreach ($menus as $key => $val) {
    if ($val['isshow'] == 1) {
        ?>
        <h2 class="navTitle"><?= $val['name'] ?></h2>
        <div  id="lm_<?php echo $key; ?>">
            <?php
            $route = $key;
            $leftMenus = $menus[$route];
            $seger = $this->uri->segment($uri + 1 , '');
            $segsan = $this->uri->segment($uri + 2 , 'index');
            //设置栏目样式
            $curleft[$seger][$segsan] = 'clscur_left';
            ?>
            <?php if ($leftMenus['isshow']): foreach ($leftMenus as $key => $val):

                if (is_array($val)): ?>

                    <?php if (true/*$rolePermission[$key . '_'] == 1 || $rolePermission[$key] == 1*/): ?>
                        <?php if ($val['isshow']): ?>
                            <div class="leftMenuTitle" d="<?= $key ?>"><?= $val['name'] ?></div>
                        <?php endif; ?>


                        <div class="left2">
                            <ul>
                                <?php foreach ($val as $k => $v):

                                    if (is_array($v) && $v['isshow']): ?>
                                        <?php

                                        $role_key = trim($v['url'] , '/');//去除头尾的斜杠
                                        $subcnt = (substr_count($role_key , '/'));//计算剩下还有多少个斜杠
                                        if ($subcnt == 1) {
                                            $role_key = trim(strstr($role_key , '/') , '/') . '_';
                                        }
                                        elseif ($subcnt == 2) {
                                            $role_key = trim(strstr($role_key , '/') , '/');
                                        }
                                        $role_key = str_replace('/' , '_' , $role_key);

                                        if ($rolePermission[$role_key] == 1): ?>
                                            <li data-route="<?php echo $route; ?>"
                                                id="<?= str_replace('/' , '_' , $v['url']) ?>"
                                                data-rrole="<?= $role_key; ?>" class="<?= $key ?>"><a
                                                        href="<?= blang_url($v['url']); ?>"><?= $v['name'] ?></a>
                                            </li>
                                        <?php endif; ?>
                                    <?php endif; endforeach; ?>
                            </ul>
                        </div>


                    <?php endif;endif;
            endforeach;
            endif; ?>
        </div>
        <?php
    }

}

?>
</div>
<?php
//接翁研娜传达的陈曦的要求
//维修报表（维修点KPI——耗时，维修点KPI——数量）——由于是内测版，数据还未计算，先设置权限为陈曦，妍娜，Jay 可见
//2017/01/24 sqingwen
$arr_acc = array('jay' , 'Belle' , 'chenxi','prezwang');
$ro_acc = $this->users['account'];
if (!in_array($ro_acc , $arr_acc)) {
    ?>
    <script type="text/javascript">
        $('#maintainReport_maintainReport_repairComprehensiveKpi').remove();
        $('#maintainReport_maintainReport_repairComprehensiveKpiNum').remove();
    </script>

    <?php
}
?>

    <script type="text/javascript">
        var cur_nav = 'lm_<?php echo($segmens)?>';
        var cnt_hid = 0;
        var cur_id = $('#<?= $cur_data_id ?>').attr('data-route')
        if (cur_id == undefined) {
            cur_id = $('#<?= $cur_data_id ?>_').attr('data-route');
            $('#<?= $cur_data_id ?>_ >a').addClass("clscur_left");
        }
       
        $('#<?= $cur_data_id ?>>a').addClass("clscur_left");
        //window.location.href = $('.top3 > .nav > ul >li:first-child a').attr('href')
        // alert();

        //给头部的菜单赋链接地址
        $('#ttopnav>li>a').each(function () {
            var id = $(this).attr('data-id');
            var hr = $('#' + id + '>.left2>ul>li:first>a').attr('href');
            $(this).attr('href', hr);
        });

        //检查leftMenuTitle是否有子菜单，没有这关闭

        $('.leftMenuTitle').each(function () {
            var tt = $(this).attr('d');
            var cnt = $('.' + tt).size();
            if (cnt == 0) {
                $(this).hide();
            }
            //alert($('.' + tt).html() + ':' +);
        });
    </script>

